; The Help Desk Macro

formatPhone(phone)
{
   ; standardize the phone number format
   Loop                                                            
   {
      StringReplace, phone, phone, (,, All
      StringReplace, phone, phone, ),, All
      StringReplace, phone, phone, -,, All
      StringReplace, phone, phone, %A_Space%,, All
      StringReplace, phone, phone, .,, All
      StringReplace, phone, phone, ',,,All
      StringReplace, phone, phone, +,, All
      StringReplace, phone, phone, /,, All
      StringReplace, phone, phone, *,, All
      StringReplace, phone, phone, a,, All
      StringReplace, phone, phone, b,, All
      StringReplace, phone, phone, c,, All
      StringReplace, phone, phone, d,, All
      StringReplace, phone, phone, e,, All
      StringReplace, phone, phone, f,, All
      StringReplace, phone, phone, g,, All
      StringReplace, phone, phone, h,, All
      StringReplace, phone, phone, i,, All
      StringReplace, phone, phone, j,, All
      StringReplace, phone, phone, k,, All
      StringReplace, phone, phone, l,, All
      StringReplace, phone, phone, m,, All
      StringReplace, phone, phone, n,, All
      StringReplace, phone, phone, o,, All
      StringReplace, phone, phone, p,, All
      StringReplace, phone, phone, q,, All
      StringReplace, phone, phone, r,, All
      StringReplace, phone, phone, s,, All
      StringReplace, phone, phone, t,, All
      StringReplace, phone, phone, u,, All
      StringReplace, phone, phone, v,, All
      StringReplace, phone, phone, w,, All
      StringReplace, phone, phone, x,, All
      StringReplace, phone, phone, y,, All
      StringReplace, phone, phone, z,, All
      StringReplace, phone, phone, A,, All
      StringReplace, phone, phone, B,, All
      StringReplace, phone, phone, C,, All
      StringReplace, phone, phone, D,, All
      StringReplace, phone, phone, E,, All
      StringReplace, phone, phone, F,, All
      StringReplace, phone, phone, G,, All
      StringReplace, phone, phone, H,, All
      StringReplace, phone, phone, I,, All
      StringReplace, phone, phone, J,, All
      StringReplace, phone, phone, K,, All
      StringReplace, phone, phone, L,, All
      StringReplace, phone, phone, M,, All
      StringReplace, phone, phone, N,, All
      StringReplace, phone, phone, O,, All
      StringReplace, phone, phone, P,, All
      StringReplace, phone, phone, Q,, All
      StringReplace, phone, phone, R,, All
      StringReplace, phone, phone, S,, All
      StringReplace, phone, phone, T,, All
      StringReplace, phone, phone, U,, All
      StringReplace, phone, phone, V,, All
      StringReplace, phone, phone, W,, All
      StringReplace, phone, phone, X,, All
      StringReplace, phone, phone, Y,, All
      StringReplace, phone, phone, Z,, All
      StringReplace, phone, phone, !,, All
      StringReplace, phone, phone, @,, All
      StringReplace, phone, phone, #,, All
      StringReplace, phone, phone, $,, All
      StringReplace, phone, phone, ^,, All
      StringReplace, phone, phone, &,, All
      StringReplace, phone, phone, *,, All
      StringReplace, phone, phone, %Percent%,, All


      StringLen, phoneLength, phone

      ; if the phone number is ten digits continue the program
      If (phoneLength == 10)                              
      {
         break
      }
      Else
      {
         InputBox, phone, Reprompt, Enter a ten digit phone number,,,, Xpos + 500, YPos + 300
         if ErrorLevel = 1
            Exit
      }
   }

   Loop
   {
      StringLeft, areaCode, phone, 3
      StringMid, firstPartPhone, phone, 4, 3
      StringRight, lastFourPhone, phone, 4

      realPhone = (%areaCode%) %firstPartPhone%-%lastFourPhone%

      StringLen, phoneLength, realPhone

      If (phoneLength == 14)
      {
         Break
      }
      Else
      {
         MsgBox not long enough
      }
   }
   Return realPhone
}

createAsset(assetName, realPhone, manufacturer, model, serial, OS, items, password, yCoord)
{
   ; click 'Assets'
   MouseMove 35, yCoord+147                                      
   Click

   StatusBarWait, Done
   StatusBarWait, Done
   Sleep 2500
   ImageSearch, newAssetX, newAssetY,153,800,500,1000, *100 C:\HotKeyImageSearch\CreateAsset.bmp
   MouseMove newAssetX+20, newAssetY+10
   Click

   StatusBarWait, Done
   Sleep 2000

   MouseMove 276, yCoord+105
   Click

   Send %assetName%

   MouseMove 1000, yCoord+107
   Click

   sleep 100

   Send %realPhone%

   MouseMove 300, yCoord+162
   Click

   Send {raw}%manufacturer%

   MouseMove 630, yCoord+167
   Click

   Send {raw}%model%

   MouseMove 1000, yCoord+167
   click

   Send {raw}%serial%

   MouseMove 1000, yCoord+194 
   Click

   Send {raw}%OS%

   MouseMove 285, yCoord+292
   Click

   Send Left: {raw}%items% 
   Send {Return}
   Send Password: {raw}%password%

   MsgBox Save Asset? (press windows+x otherwise)

   MouseMove 202, yCoord+412
   click

   StatusBarWait, Done
   Sleep 2500

   loop
   {
      ImageSearch,,,0,0,1000,1000, *TransWhite *100 C:\HotKeyImageSearch\assetExists.bmp
      if ErrorLevel = 0
      {
         InputBox, assetName,, Asset already exists.  Type in a slightly different name (i.e lastname`, firstname1) for this asset:
         {
            MouseMove 342, yCoord+147
            Click
            Send ^a 
            Send {raw}%assetName%

            MsgBox Save Asset? (press windows+x otherwise)

            MouseMove 207, yCoord+454
            Click

            StatusBarWait, Done
            Sleep 2500
         }
      }
      else
         Break
   }
   Return assetName
}

   ; fill out a clipboard wireless ticket after filling out the name
   #space::                           
   Click 353, 353
   Send Tech - Wireless Issues
   Click 800, 438
   Send Wireless issues{tab}{tab}l{tab}w{tab}b{tab}hhhh{tab}{tab}{tab}c{tab}c
   Click 193, 228

   exit

   ; Create a new incident
   #alt::                            
   Click 49, 362

   exit

   ; Save an incident
   #z::                               
   Click 193, 228
   Exit

   ; Pharos printing install ticket from clipboard after finding name
   #p::                               
   Click 353, 353
   Send Tech - Pharos install
   Click 306, 450
   Send Pharos install{tab}{tab}l{tab}w{tab}{tab}hhhhh{tab}{tab}{tab}c{tab}c
   Click 193, 228

   ; reload this whole script
   #x::                               
   Reload

   Exit

   ; fill out a warranty ticket from scratch
   #w::                              


   ImageSearch ,x,yCoord, 0,0,1000,1000, *TransWhite *100 C:\HotKeyImageSearch\Altiris.bmp

   if ErrorLevel = 0
   {
   }
   else
   {
      Gui, Add, Text,, This form only works in IE7 with only 
      Gui, Add, Text,, the google toolbar and tabs showing, like this:
      Gui, Add, Pic,, C:\HotKeyImageSearch\howIE.bmp
      Gui, Add, Button,, Cancel
      Gui, Show, AutoSize, Sorry
      return
   }

   WinGetActiveStats, Title, Width, Height, Xpos, Ypos ; get the position of the active window

   Gui, Add, Tab2, w325 h475, Warranty|Dropping off for work|Clipboard

   Gui, Tab, 1

   ; create fields for the warranty form
   Gui, Add, Text, x20 y30, First name:                 
   Gui, Add, Edit, x20 y50 w100 vfirstName

   Gui, Add, Text, x170 y30, Last name:
   Gui, Add, Edit, x170 y50 w100 vlastName

   Gui, Add, Text, x20 y75, Phone number:
   Gui, Add, Edit, x20 y95 w100 vphone

   Gui, Add, Text, x170 y75, Full Address:
   Gui, Add, Edit, x170 y95 w100 vaddress

   Gui, Add, Text, x20 y130, Manufacturer:
   Gui, Add, Edit, x20 y150 w100 vmanufacturer

   Gui, Add, Text, x170 y130, Model:
   Gui, Add, Edit, x170 y150 w100 vmodel

   Gui, Add, text, x20 y175, Serial Number
   Gui, Add, Edit, x20 y195 w100 vserial

   Gui, Add, Text, x170 y175, OS:
   Gui, Add, Edit, x170 y195 w100 vOS

   Gui, Add, Text, x20 y220, Password:
   Gui, Add, Edit, X20 y235 w100 vpassword

   Gui, Add, Text, x20 y260, What did they leave behind?
   Gui, Add, Edit, x20 y280 w300 r3 vitems

   Gui, Add, Text, x20 y330, Notes and initials of technician:
   Gui, Add, Edit, x20 y350 w300 r5 vnotes

   ;create buttons
   Gui, Add, Button,x20 y430 Default, OK                              
   Gui, Add, Button,x145 y430, Cancel

   Gui, Tab, 2

   ; create fields for the "leaving for work" form
   Gui, Add, Text, x20 y30, First name:                 
   Gui, Add, Edit, x20 y50 w100 vfirstNameUs

   Gui, Add, Text, x170 y30, Last name:
   Gui, Add, Edit, x170 y50 w100 vlastNameUs

   Gui, Add, Text, x20 y75, Phone number:
   Gui, Add, Edit, x20 y95 w100 vphoneUs

   Gui, Add, Text, x170 y75, Short problem description
   Gui, Add, Edit, x170 y95 vproblemUs

   Gui, Add, Text, x20 y130, Manufacturer:
   Gui, Add, Edit, x20 y150 w100 vmanufacturerUs

   Gui, Add, Text, x170 y130, Model:
   Gui, Add, Edit, x170 y150 w100 vmodelUs

   Gui, Add, text, x20 y175, Serial Number
   Gui, Add, Edit, x20 y195 w100 vserialUs

   Gui, Add, Text, x170 y175, OS:
   Gui, Add, Edit, x170 y195 w100 vOSUs

   Gui, Add, Text, x20 y220, Password:
   Gui, Add, Edit, X20 y235 w100 vpasswordUs

   Gui, Add, Text, x20 y260, What did they leave behind?
   Gui, Add, Edit, x20 y280 w300 r3 vitemsUs

   Gui, Add, Text, x20 y330, Notes and initials of technician:
   Gui, Add, Edit, x20 y350 w300 r5 vnotesUs

   ;create buttons
   Gui, Add, Button,x20 y430 Default, Send                              
   Gui, Add, Button,x145 y430, Cancel

   Gui, Tab, 3

   ; create fields for the "leaving for work" form
   Gui, Add, Text, x20 y30, First name:                 
   Gui, Add, Edit, x20 y50 w100 vfirstNameCB

   Gui, Add, Text, x170 y30, Last name:
   Gui, Add, Edit, x170 y50 w100 vlastNameCB

   Gui, Add, Text, x20 y330, What was the problem?
   Gui, Add, Edit, x20 y350 w300 r5 vproblemCB

   ;create buttons
   Gui, Add, Button,x20 y430 Default, ClipBoard                              
   Gui, Add, Button,x145 y430, Cancel

   ;automatically size the form
   Gui, Show, X%Xpos% Y%Ypos% AutoSize, Form                                          
   return

   ; when 'ok'is pushed save the form info
   ButtonOK:
   Gui, Submit                                                        

   assetName = %lastName%, %firstName%

   realPhone := formatPhone(phone)

   assetName := createAsset(assetName, realPhone, manufacturer, model, serial, OS, items, password, yCoord)

   ImageSearch ,x,yCoord, 0,0,1000,1000, *TransWhite *100 C:\HotKeyImageSearch\Altiris.bmp

   ; create an incident
   MouseMove 49, yCoord+240                                      
   Click
 
   StatusBarWait, Done
   Sleep 2500

   MouseMove 638, yCoord+143
   Click

   Send %lastName%, %firstName% {Return}
   MsgBox Click OK when the customer is the chosen contact  ; make sure the contact is correct

   MouseMove 800, yCoord+133
   Click

   StatusBarWait, Done
   Sleep 2500

   MouseMove 300, yCoord+520
   Click

   StatusBarWait, Done
   Sleep 1500

   MouseMove 670, yCoord+200
   Click

   Send ^a
   ; update contact phone number
   Send %realPhone%                                          

   MouseMove 225, yCoord+440
   Click

   StatusBarWait, Done
   Sleep 2000

   MouseMove 630, yCoord+165
   Click
   Send {raw}%assetName% 
   ; associate asset with ticket
   Send {Return}                      

   MsgBox Click OK when the asset is correctly chosen

    ; fill out incident
   MouseMove 325, yCoord+233                                            
   Click
   Send WR-%lastName% %realPhone%

   MouseMove 500, yCoord+288
   Click
   Send %address% {Return}{Return}
   Send %notes%

   MouseMove 400, yCoord+380
   Click
   Send l{tab}{tab}ssssss{tab}ssssss{tab}a

   MsgBox verify the information is accurate and save the incident

   Gui Destroy
   Exit

   ButtonSend:
   Gui Submit

   assetNameUs = %lastNameUs%, %firstNameUs%

   realPhone := formatPhone(phone)

   assetName := createAsset(assetNameUs, realPhone, manufacturerUs, modelUs, serialUs, OSUs, itemsUs, passwordUs, yCoord)

   ; create an incident
   MouseMove 49, yCoord+240                                      
   Click

   StatusBarWait, Done
   Sleep 2500

   MouseMove 638, yCoord+143
   Click

   Send %lastNameUs%, %firstNameUs% {Return}
   ; make sure the contact is correct
   MsgBox Click OK when the customer is the chosen contact  

   MouseMove 630, yCoord+165
   Click
   Send {raw}%assetNameUs% 
   ; associate asset with ticket
   Send {Return}                      

   MsgBox Click OK when the asset is correctly chosen

   ; fill out incident
   MouseMove 325, yCoord+233                                             
   Click
   Send Tech - %problemUs%

   MouseMove 500, yCoord+288
   Click
   Send %notesUs%

   MouseMove 400, yCoord+380
   Click
   Send l{tab}{tab}hhhhh

   MsgBox verify the information is accurate and save the incident

   Gui Destroy
   Exit


   ButtonClipBoard:
   Gui Submit

   ; create an incident
   MouseMove 49, yCoord+240                                      
   Click

   StatusBarWait, Done
   Sleep 2500

   MouseMove 638, yCoord+143
   Click

   Send %lastNameCB%, %firstNameCB% {Return}
   MsgBox Click OK when the customer is the chosen contact  ; make sure the contact is correct

   ; fill out incident
   MouseMove 325, yCoord+233                                             
   Click
   Send Tech - Clipboard

   MouseMove 500, yCoord+288
   Click
   Send %problemCB%

   MouseMove 400, yCoord+380
   Click
   Send l{tab}{tab}hhhhh{tab}{tab}{tab}c{tab}c

   Gui Destroy
   Exit

   ButtonCancel:
   Gui Destroy
   Exit